Screen('Preference', 'SkipSyncTests', 2);
screenNum =0;
res = [1360 768];
clrDepth = 32
[wPtr, rect] = Screen('OpenWindow', screenNum, 0, [0 0 res(1) res(2)], clrDepth)


black=BlackIndex( wPtr );
white=WhiteIndex( wPtr );
Screen('FillRect' , wPtr , black );
Screen( wPtr , 'Flip' );

HideCursor;
tic
refresh= Screen('GetFlipInterval', wPtr);



color = white
vec = [rect(3) rect(4)]
ovalRect = [340 192 1020 576]

vbl = Screen(wPtr, 'Flip');
t0 = GetSecs
keysOfInterest=zeros(1 ,256);
keysOfInterest(KbName( 'space')) =1;

KbQueueCreate(-1, keysOfInterest);
while KbCheck; end;


KbQueueStart(-1);


t = 0
while ( GetSecs < t0 + 0.5  )
  
end

x= []
y = []
    
for i=1:50

    Screen('FillOval', wPtr, color, ovalRect);
    vbl = Screen( 'Flip' , wPtr , vbl + 0.5);
    
    Screen('FillRect', wPtr, black);
    Screen('Flip', wPtr, vbl + (10-0.1)*refresh);
    
    waitSecs(0.1);
    
    y = [y vbl]
    [pressed first] = KbQueueCheck(-1)    
    
    if pressed
        x= [x first(find(first))]
    else
        x = [x nan]
    end    
end


% 
% while toc <3
%     ;
% end
% Screen( 'FillOval' , wPtr , [255 0 0], [1 1 50 50]);
% Screen( wPtr , 'Flip' );
% HideCursor;
% 
% tic
% while toc <3
% ;
% end
% 
Screen( 'CloseAll');
ShowCursor;
